package controller;


import POJO.AppInfo;
import POJO.AppVersion;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.AppCategoryService;
import service.AppInfoService;
import service.AppVersionService;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class AppVersionController {
    @Resource
    private AppInfoService appInfoService;
    @Resource
    private AppVersionService appVersionService;
    @Resource
    private AppCategoryService appCategoryService;
  //  @RequestMapping("/appVersionListss")
//    public String appVersionLists(Integer appid, Model model){
//        if(appid==null){
//            appid=55;
//        }
//        model.addAttribute("appVersion","addappVersion");
//       List<AppVersion> appVersionList= appVersionService.AppVersionList(appid);
//        model.addAttribute("appVersionList",appVersionList);
//        model.addAttribute("appid",appid);
//        return  "index";
//    }
    @RequestMapping("/AppVersionList")
    public  String AppVersionList(Integer appid,Model model){
        model.addAttribute("appVersiondappid","addappVersionappid");
        List<AppVersion> appVersionList= appVersionService.AppVersionList(appid);
        model.addAttribute("appVersionList",appVersionList);
        model.addAttribute("appid",appid);
        return  "indexss";
    }
    @RequestMapping("/UpdateAppVersion")
    @ResponseBody
    public int UpdateAppVersion(AppVersion appVersion){
    int update=appVersionService.UpdateAppVersion(appVersion);
    return update;
    }
//    @RequestMapping("/updateVersion")
//    public String updateVersion(Integer appid, Model model){
//        Map<String,Object>  appVersions=new HashMap<String,Object>();
//       // model.addAttribute("appVersionss","UpdateAppVersion");
//        List<AppVersion> appVersionList= appVersionService.AppVersionList(appid);
//       // model.addAttribute("appVersionList",appVersionList);
//      AppVersion appVersion=appVersionService.AppVersionID(appid);
//        appVersions.put("appVersionss","UpdateAppVersion");
//        appVersions.put("selectappVersiona",appVersion);
//        appVersions.put("appid",appid);
//        appVersions.put("appVersionList",appVersionList);
//        model.addAttribute("appVersions",appVersions);
//      // model.addAttribute("selectappVersiona",appVersion);
//       // model.addAttribute("appid",appid);
//        return "index";
//    }
    @RequestMapping("/ShowaddAppInfoAppVersion")
    public String ShowaddAppInfoAppVersion(Integer appId,Model model){
        model.addAttribute("ShowaddAppInfoAppVersion","ShowaddAppInfoAppVersion");
        List<AppVersion> appVersionList= appVersionService.AppVersionList(appId);
        model.addAttribute("appVersionList",appVersionList);
        AppInfo appInfo=new AppInfo();
        appInfo=appInfoService.appInfoListId(appId);
        model.addAttribute("appInfo",appInfo);
        model.addAttribute("getCategoryLevel2",appCategoryService.getAppCategoryByPrintId(appInfo.getCategoryLevel1()));
        model.addAttribute("getCategoryLevel3",appCategoryService.getAppCategoryByPrintId(appInfo.getCategoryLevel2()));

        return "indexss";
    }

    @RequestMapping("/ShowupdateVersionList")
    public String ShowupdateVersionList(Integer appId,Model model){
        model.addAttribute("ShowupdateVersionList","ShowupdateVersionList");
        List<AppVersion> appVersionList= appVersionService.AppVersionList(appId);

        model.addAttribute("appVersionList",appVersionList);
        AppVersion appVersion=appVersionService.AppVersionID(appId);
        model.addAttribute("appVersion",appVersion);
        model.addAttribute("appid",appId);
        return  "indexss";
    }

    @RequestMapping("/versionList")
    @ResponseBody
    public int VersionList(Integer appid){
        int VersionListSize= appVersionService.AppVersionList(appid).size();
     //   String appVersionListJson= JSONArray.toJSONString(appVersionList);
        return  VersionListSize;
    }
//    @RequestMapping("/updateAppVersion")
//    @ResponseBody
//    public int updateAppVersionlist(Integer appid){
//    int AppVersion=appVersionService.AppVersionList(appid).size();
//
//
//    }

    @RequestMapping("/addAppVersion")
    @ResponseBody
    public int AddAppVersion(AppVersion appVersion){
int insertAppVersion=appVersionService.AddAppVersion(appVersion);
System.out.print(insertAppVersion);
return insertAppVersion;
    }


}
